home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 14.1 KB | 428 lines | [TEXT/MPS ] |
- // USection.h
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
-
- #ifndef __USECTION__
- #define __USECTION__
-
- //----------------------------------------------------------------------------------------
- // Unit: USection
- //
- // OVERVIEW
- //
- // TSection is designed to provide Edition Manager support. TSection is an abstract
- // superclass which references the main Edition Manager data structure (the
- // SectionHandle), and a designator (designating which portion of the document is
- // published/ subscribed). Specialized subclasses of TSection are required to represent the
- // TPublisher and TSubscriber.
- //
- // CLASS HIERARCHY
- //
- // TSection abstract superclass for sections
- // TPublisher an Edition Manager publisher
- // TSubscriber an Edition Manager subscriber
- //
- // USAGE
- //
- // TPublisher/ TSubscriber is designed to be used with the Edition Manager support that is
- // built into MacApp. Whenever a portion of the document is publisher/ subscribed, a
- // TSection object is instantiated. The TSection object references a TDesignator.
- //----------------------------------------------------------------------------------------
-
- // MacApp
-
- #ifndef __ULIST__
- #include "UList.h"
- #endif
-
- #ifndef __UOBJECT__
- #include "UObject.h"
- #endif
-
- #ifndef __USTREAM__
- #include "UStream.h"
- #endif
-
- // Toolbox
-
- #ifndef __EDITIONS__
- #include <Editions.h>
- #endif
-
-
- //----------------------------------------------------------------------------------------
- // Forward and external class declarations.
- //----------------------------------------------------------------------------------------
-
- class TDesignator;
- class TEditionDocument;
- class TFile;
-
-
- //----------------------------------------------------------------------------------------
- // Constants
- //----------------------------------------------------------------------------------------
-
- const Boolean kEditionFound = TRUE; // the edition file was found
-
- const Boolean kEditionNotFound = FALSE; // the edition file wasn't found
-
-
- //----------------------------------------------------------------------------------------
- // passed into TSection::CancelSection()
- //----------------------------------------------------------------------------------------
-
- const Boolean kCancel = TRUE; // cancel the section
-
- const Boolean kDontCancel = FALSE; // don't cancel the section
-
-
- //----------------------------------------------------------------------------------------
- // Section Change ID's
- //----------------------------------------------------------------------------------------
-
- const ChangeID cSubscriberChanged = 610; // change id indicating that the
- // subscriber changed
-
- const ChangeID cPublisherChanged = 611; // change id indicating that the publisher
- // changed
-
-
- //----------------------------------------------------------------------------------------
- // TSection: TSection is an abstract superclass providing common support for sections -
- // both subscribers and publishers.
- //----------------------------------------------------------------------------------------
-
- class TSection : public TObject
- {
- MA_DECLARE_CLASS;
-
- public:
- TEditionDocument* fDocument; // the document that owns this section
-
- TDesignator* fDesignator; // the designated portion of the document
-
- SectionHandle fSectionHandle; // reference to the section record for
- // this edition
-
- short fRsrcID; // rsrc id of stored form (needed for
- // Read)
-
- EditionInfoRecord fLastEditionInfo; // stored at various points for later use
-
- Boolean fCanceled; // whether this section is canceled
-
- Boolean fFound; // whether this edition was found by
- // RegisterSection
-
- Boolean fNewSection; // this is a brand spankin' new section
-
-
- //------------------------------------------------------------------------------------
- // ••• contructors/destructors •••
- //------------------------------------------------------------------------------------
-
- TSection();
- // Empty constructor to satisfy compiler.
-
- void ISection(TEditionDocument* itsDocument,
- TDesignator* itsDesignator,
- SectionHandle itsSectionHandle,
- short itsRsrcID);
- // initializes the edition object
-
- virtual ~TSection();
- // calls Unregister, disposes the SectionHandle and AliasHandle
-
-
- //------------------------------------------------------------------------------------
- // ••• data accessors •••
- //------------------------------------------------------------------------------------
-
- virtual void AttachSectionHandle(SectionHandle itsSectionHandle);
- // attach a SectionHandle to this TSection object
-
- virtual void GetEditionName(CStr255& name);
- // Returns the name of the edition container file.
-
- // virtual TFileHandler* GetFileHandler();
- // // returns the TFileHandler of the document with which this section is associated
-
- virtual SectionType GetSectionType();
- // returns the (*fSectionHandle)->kind
-
- virtual UpdateMode GetUpdateMode();
- // returns the (*fSectionHandle)->mode
-
-
- //------------------------------------------------------------------------------------
- // ••• saving/restoring •••
- //------------------------------------------------------------------------------------
-
- virtual void DoWrite(TFile* aFile, Boolean makingCopy);
- // writes the section handle as a sect resource and the alias handle as a alis
- // resource
-
- virtual void DoRead(TFile* aFile);
- // reads the section handle from a sect resource and the alias handle from a alis
- // resource
-
- virtual void DoNeedDiskSpace(long& dataForkBytes, long& rsrcForkBytes);
- // Bytes required to store saved sections on disk. When called, both parameters
- // are set to 0 for you.
-
- virtual void Associate(TFile* aFile);
- // call this to associate the section handle with a new section document
-
-
- //------------------------------------------------------------------------------------
- // ••• miscellaneous •••
- //------------------------------------------------------------------------------------
-
- virtual void Delete();
- // removes the section resources
-
- virtual TFile* GetCurrentFile(TFile* aFile);
- // given a file being written to in DoWrite, this returns the correct file
-
- virtual Boolean IsCanceled();
- // returns fCanceled
-
- virtual Boolean IsChanged();
- // returns true if the mdDate of the SectionRecord is newer than the mdDate of the
- // edition on disk
-
- virtual Boolean IsRegistered();
- // returns true if fRegistered & (IsRegisteredSection returns noErr)
-
- virtual void MarkAsChanged();
- // marks this publisher as changed; should be called each time the user edits the
- // data in the publisher
-
- virtual OSErr Register();
- // calls RegisterSection on the Section Handle and sets fRegisteredSection
-
- virtual void UnRegister();
- // calls UnRegisterSection on the Section Handle and sets fRegisteredSection
-
- virtual void UpdateEditionInfo();
- // updates fEditionInfo for later use
-
- virtual void CancelSection(Boolean cancel);
- // if cancel is true then calls UnRegister and sets fCanceled to true else if
- // cancel is false then calls Register and sets fCanceled to false
- };
-
-
- //----------------------------------------------------------------------------------------
- // TPublisher: each instance of this class represents a part of the document that is
- // published
- //----------------------------------------------------------------------------------------
-
- class TPublisher : public TSection
- {
- MA_DECLARE_CLASS;
-
- public:
-
- //------------------------------------------------------------------------------------
- // ••• contructors/destructors •••
- //------------------------------------------------------------------------------------
-
- TPublisher();
- // Empty constructor to satisfy compiler.
- virtual ~TPublisher();
- // Destructor
-
- void IPublisher(TEditionDocument* itsDocument,
- TDesignator* itsDesignator,
- SectionHandle itsSectionHandle,
- short itsRsrcID);
- // initializes a publisher object
-
-
- //------------------------------------------------------------------------------------
- // ••• change notification •••
- //------------------------------------------------------------------------------------
-
- virtual void DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace);
- // marks this publisher as changed calling MarkAsChanged
-
-
- //------------------------------------------------------------------------------------
- // ••• saving/restoring •••
- //------------------------------------------------------------------------------------
-
- virtual void Publish(TFile* aFile);
- // publishes this edition to the edition file
-
- virtual void DoWrite(TFile* aFile, Boolean makingCopy);
- // calls INHERITTED Write if (mode is pumOnSave) & IsChanged then Publish
-
-
- //------------------------------------------------------------------------------------
- // ••• miscellaneous •••
- //------------------------------------------------------------------------------------
-
- virtual void Delete();
- // deletes the edition file; called when the doc is saved if the user canceled the
- // publisher
-
- virtual void DeleteEditionFile();
- // delete the edition container file
-
- virtual Boolean IsChanged();
- // returns true if the mdDate of the SectionRecord is newer than the mdDate of the
- // edition on disk
-
- virtual void MarkAsChanged();
- // marks this publisher as changed; should be called each time the user edits the
- // data in the publisher
-
- };
-
-
- //----------------------------------------------------------------------------------------
- // TSubscriber - each instance represents a subscriber for this document.
- //----------------------------------------------------------------------------------------
-
- class TSubscriber : public TSection
- {
- MA_DECLARE_CLASS;
-
- public:
- Boolean fChanged; // whether or not this guy has changed.
-
- //------------------------------------------------------------------------------------
- // ••• contructors/destructors •••
- //------------------------------------------------------------------------------------
-
- TSubscriber();
- // Empty constructor to satisfy compiler.
- virtual ~TSubscriber();
- // Destructor
-
- void ISubscriber(TEditionDocument* itsDocument,
- TDesignator* itsDesignator,
- SectionHandle itsSectionHandle,
- short itsRsrcID);
- // initializes the subscriber object
-
-
- //------------------------------------------------------------------------------------
- // ••• saving/restoring •••
- //------------------------------------------------------------------------------------
-
- virtual void Subscribe();
- // updates this subscriber from the edition on disk
-
- virtual void SubscribeIfNewer();
- // calls Subscribe if a newer edition is available
-
-
- //------------------------------------------------------------------------------------
- // ••• miscellaneous •••
- //------------------------------------------------------------------------------------
-
- virtual Boolean IsNewerEditionAvailable();
- // return true if there is a newer version of this edition on disk
-
- virtual void OpenPublisher();
- // calls GetEditionInfo & GotoPublisherSection
-
- virtual Boolean IsChanged();
- // returns true if the mdDate of the SectionRecord is newer than the mdDate of the
- // edition on disk
-
- virtual void MarkAsChanged();
- // marks this publisher as changed; should be called each time the user edits the
- // data in the publisher
- };
-
-
- //----------------------------------------------------------------------------------------
- // TSectionStream reads data from and writes data to an already open EditionContainerFile.
- // Should be enhanced to support streaming data concurrently of various OS Types (e.g.
- // PICT, TEXT, etc) rather than simply streaming one type at a time.
- //----------------------------------------------------------------------------------------
-
- class TSectionStream : public TStream
- {
- MA_DECLARE_CLASS;
-
- public:
- EditionRefNum fEditionRefNum; // refnum of EditionContainerFile
-
- OSType fEditionOSType; // OSType to write to EditionContainerFile
-
- long fPosition; // offset into the EditionContainerFile
-
- long fSize; // size of the fEditionOSType
-
- //------------------------------------------------------------------------------------
- // ••• contructors/destructors •••
- //------------------------------------------------------------------------------------
-
- TSectionStream();
- // Constructor
- virtual ~TSectionStream();
- // Destructor
-
- void ISectionStream(EditionRefNum itsEditionRefNum, OSType itsEditionOSType);
- // Initialize the TSectionStream.
-
- //------------------------------------------------------------------------------------
- // ••• miscellaneous •••
- //------------------------------------------------------------------------------------
-
- virtual void Reset(OSType itsEditionOSType, long itsSize);
- // Resets fPosition to 0, fEditionOSType to itsEditionOSType, and fSize to
- // itsSize.
-
- virtual long GetPosition();
- // Returns fPosition.
-
- virtual void SetPosition(long newPosition);
- // Sets fPosition.
-
- virtual long GetSize();
- // Returns fSize.
-
- virtual void SetSize(long newSize);
- // Sets fSize.
-
- virtual void ReadBytes(void* p, long count);
- // Reads bytes from the Edition Container File.
-
- virtual void WriteBytes(const void* p, long count);
- // Write bytes to the Edition Container File.
- };
-
- //----------------------------------------------------------------------------------------
- // TSectionList: Subclass of TSortedList that manages a sorted list of TSection objects.
- //----------------------------------------------------------------------------------------
-
- class TSectionList : public TSortedList
- {
- MA_DECLARE_CLASS;
-
- public:
-
- TSectionList();
- // Empty constructor to satisfy compiler.
- virtual ~TSectionList();
- // Destructor
-
- void ISectionList();
- // Initialize the list
-
- virtual CompareResult Compare(TObject* item1, TObject* item2);
- // Compares 'item'1 with 'item2' returning an integer indicating the results of
- // the comparison
-
- };
-
- #endif // __USECTION__
-